package com.saihai.jiankang.ufFwjg.controller;

import com.saihai.common.annotation.Log;
import com.saihai.common.core.controller.BaseController;
import com.saihai.common.core.domain.AjaxResult;
import com.saihai.common.core.page.TableDataInfo;
import com.saihai.common.enums.BusinessType;
import com.saihai.common.utils.poi.ExcelUtil;
import com.saihai.jiankang.ufFwjg.domain.UfFwjg;
import com.saihai.jiankang.ufFwjg.service.IUfFwjgService;
import com.saihai.jiankang.ufYsgl.domain.UfYsgl;
import com.saihai.jiankang.ufYsgl.service.IUfYsglService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 服务机构Controller
 * 
 * @author ruoyi
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/jiankang/ufFwjg")
public class UfFwjgController extends BaseController
{
    @Autowired
    private IUfFwjgService ufFwjgService;

    @Autowired
    private IUfYsglService ufYsglService;

    /**
     * 查询服务机构列表
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufFwjg:list')")
    @GetMapping("/list")
    public TableDataInfo list(UfFwjg ufFwjg)
    {
        startPage();
        List<UfFwjg> list = ufFwjgService.selectUfFwjgList(ufFwjg);
        return getDataTable(list);
    }

    /**
     * 通过医生id查询服务机构
     */
    @GetMapping("/fwjgListyS/{id}")
    public AjaxResult fwjgListyS(@PathVariable("id") Long id)
    {
        UfYsgl ufYsgl =  ufYsglService.selectUfYsglById(id);

        return success(ufFwjgService.selectUfFwjgById(Long.parseLong(ufYsgl.getSzjg())));
    }

    /**
     * 导出服务机构列表
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufFwjg:export')")
    @Log(title = "服务机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UfFwjg ufFwjg)
    {
        List<UfFwjg> list = ufFwjgService.selectUfFwjgList(ufFwjg);
        ExcelUtil<UfFwjg> util = new ExcelUtil<UfFwjg>(UfFwjg.class);
        util.exportExcel(response, list, "服务机构数据");
    }

    /**
     * 获取服务机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufFwjg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ufFwjgService.selectUfFwjgById(id));
    }

    /**
     * 新增服务机构
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufFwjg:add')")
    @Log(title = "服务机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UfFwjg ufFwjg)
    {
        return toAjax(ufFwjgService.insertUfFwjg(ufFwjg));
    }

    /**
     * 修改服务机构
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufFwjg:edit')")
    @Log(title = "服务机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UfFwjg ufFwjg)
    {
        return toAjax(ufFwjgService.updateUfFwjg(ufFwjg));
    }

    /**
     * 删除服务机构
     */
    @PreAuthorize("@ss.hasPermi('jiankang:ufFwjg:remove')")
    @Log(title = "服务机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ufFwjgService.deleteUfFwjgByIds(ids));
    }
}
